TR_Data <- read_csv("Total Reach Analysis.csv")
##
## -- Column specification -------------------------------------------------------------------------------------------------
## cols(
## Country = col_character(),
## `2019` = col_number(),
## `2018` = col_number(),
## `2017` = col_number(),
## `2016` = col_number()
## )
TR1 <- TR_Data %>%
gather("year", "TR", 2:5)
I wanted to find a way to visualize and compare a fairly large amount of information in a simple way. I also wanted to display it fairly, as it could diminish the reach of countries with smaller programs and less funding if they were compared to larger countries with bigger budgets and larger reach. Rather it made more sense to create an even playing field by visualizing data in the context of historical reach of one country, rather than against the figures of another.
I was looking
#heatmap
#Calculate 25th and 75th percentiles of data.
#Below 25th P is low, above 75th P is high and in between 25th AND 75th Percentiles is average.
TR_perc <- TR1 %>%
group_by(Country) %>% mutate(TR_factor = cut(TR, quantile(TR, c(0, .25, .75, 1)),
labels = c('Low', 'Medium', 'High'),
include.lowest = TRUE))
#Set gradient colors for categorical variables
colors <- c("Low" = "slategray2" , "Medium" = "slategray3", "High" = "slategray4")
TR_tile <- ggplot(TR_perc, aes(Country, year, text = paste0(
"<b>","Country:", Country, "</b>", "<br>",
"Year:", year, "<br>",
"Designation: ", TR_factor, "<br>",
"Total Reach: ", scales::comma(TR, 1), "<br>"))) +
geom_tile(aes(fill = TR_factor),colour = "white", na.rm = TRUE) +
scale_fill_manual(values = colors) +
guides(fill=guide_legend(title="Total Reach", title.vjust = -20, label.vjust = 5)) +
theme_minimal() +
labs(y = "year", x = "") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
coord_flip()
ggplotly(TR_tile, tooltip = c("text")) %>%
config(displayModeBar = F) %>%
layout(legend = list(orientation = "h", x = 0.4, y = -0.2))